fix(changelog): handle triple-backtick code fences in sanitizeChangelogEntry#13724
fix(changelog): handle triple-backtick code fences in sanitizeChangelogEntry#13724devin-ai-integration[bot] wants to merge 2 commits into
Conversation
The sanitizer only split on single-backtick inline code spans, so triple-backtick fenced code blocks (common in Java changelog entries) threw off backtick parity. This caused later inline code spans like `onMessage(Consumer<String>)` to be treated as plain text, and Consumer<String> got double-wrapped in backticks — breaking MDX parsing in the docs repo. Fix: split on fenced code blocks first (preserving them verbatim), then process each remaining segment with the existing inline-backtick logic. Co-Authored-By: unknown <>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.
Once credits are available, reopen this pull request to trigger a review.
| // First, split on triple-backtick fenced code blocks so they are never | ||
| // processed by the inline-backtick logic (which only understands single | ||
| // backtick pairs and gets confused by the three-backtick delimiters). | ||
| const fenceParts = entry.split(/(```[\s\S]*?```)/g); |
There was a problem hiding this comment.
The regex /(```[\s\S]*?```)/g will incorrectly split fenced code blocks that contain triple backticks in their content. For example, a changelog entry like:
Example:
```js
const example = "```";
The regex will match from the opening ``` to the first ``` inside the string literal, breaking the fence mid-block. The remaining text `";\n``` ` will be treated as plain text and incorrectly processed.
**Fix:** Use a more specific regex that matches the fence opening with optional language identifier:
```typescript
const fenceParts = entry.split(/(```[^\n]*\n[\s\S]*?\n```)/g);
Or handle the newline requirement:
const fenceParts = entry.split(/(```(?:[^`]|`(?!``))*```)/gs);| const fenceParts = entry.split(/(```[\s\S]*?```)/g); | |
| const fenceParts = entry.split(/(```[^\n]*\n[\s\S]*?\n```)/g); |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Good catch — applied the suggested stricter regex /(```[^\n]*\n[\s\S]*?\n```)/g in c432cd1. This requires newlines around the fence content, preventing triple backticks inside a string literal from prematurely terminating the match.
Address Graphite review: require newlines around fence content so that triple backticks inside code (e.g. a string literal containing ```) do not prematurely terminate the match. Co-Authored-By: unknown <>
Description
Refs fern-api/docs#4342
Fixes a bug where
sanitizeChangelogEntrydouble-wrapped angle-bracket types (e.g.,Consumer<String>) in backticks when the changelog entry contained a fenced code block. This caused MDX parsing failures in the docs repo (the<String>was interpreted as a JSX tag).Changes Made
sanitizeChangelogEntry, preserving them verbatim before processing remaining text with the existing inline-backtick logicsanitizeInlineParthelperRoot Cause
The function split only on single-backtick spans (
`...`). When a changelog entry contained a```java...```block, the triple backticks confused the single-backtick regex, throwing off parity. Segments that should have been recognized as "inside backticks" were treated as plain text, causingwrapAngleBracketTypesto add redundant backticks around types likeConsumer<String>.The approach mirrors what
angleBracketValidator.tsalready does — strip fenced blocks before processing inline code.Updates since last revision
/(```[\s\S]*?```)/gto/(```[^\n]*\n[\s\S]*?\n```)/gper Graphite review feedback. The stricter regex requires newlines around fence content, preventing triple backticks inside a string literal (e.g.,const x = "```") from prematurely terminating the match.Testing
@fern-api/core-utilsstill passbiome checkpassesHuman Review Checklist
/(```[^\n]*\n[\s\S]*?\n```)/ghandles all expected fenced block formats (e.g., with/without language identifier, trailing whitespace)generators/java/sdk/versions.yml(which triggered the original docs CI failure) would now produce correct MDX output when the changelog generation pipeline runsLink to Devin session: https://app.devin.ai/sessions/5151f683b2dd4b19b266c84cb1aa999a